package org.bookie.hibernate.config.entries;

import org.bookie.hibernate.config.ApplicableElement;
import org.bookie.hibernate.config.ConfigElement;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Implemenation of the {@link ConfigElement} that sets the contributed
 * hibernate property. Please note that property name set into the
 * {@link AnnotationConfiguration} object are prefixed with "hibernate."
 * 
 * @author schultma
 */
public class PropertyElement implements ApplicableElement {

	private String name;

	private String value;

	/**
	 * Setter for name called by hivemind
	 * 
	 * @return
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Setter for name called by hivemind
	 * 
	 * @return
	 */
	public void setValue(String value) {
		this.value = value;
	}
	
	public String getName() {
		return name;
	}
	
	public String getValue() {
		return value;
	}

	/**
	 * Sets the configured property in to {@link AnnotationConfiguration}
	 * 
	 * @param config
	 *            configuration
	 */
	public void applyTo(AnnotationConfiguration config) {
		config.setProperty("hibernate." + name, value);
	}
	
	@Override
	public String toString() {
		return "HibernateProperty(" + name + "=" + value + ")";
	}
}
